from Wzx.wzx9_25.gjz.Base import Base
import pytest,openpyxl
from selenium import webdriver

@pytest.fixture
def driver():
    #指定浏览器
    driver = webdriver.Edge()
    #窗口最大化
    driver.maximize_window()
    #返回数据
    yield driver
    #退出驱动
    driver.quit()

def test_jiuxian_01(driver):
    #加载excel内容
    work = openpyxl.load_workbook('./jiuixian.xlsx')
    #指定运行
    exal = work['Sheet1']

    #初始化驱动
    base = Base(driver)
    #循环查询数据
    for row in exal.iter_rows(min_row=2,values_only=True):
        #从第二行开始
        action = row[2]
        #存储值
        params = {}

        #打开网址
        if action == 'goto':
            params['url'] = row[4]
        #元素定位操作
        elif action in ['click','send_keys','text']:
            params['loc'] = [row[3] , row[4] ]
            #输入内容
            if action == 'send_keys':
                params['text'] = row[5]
        #强制等待时间
        elif action == 'sleep':
            params['timeout'] = row[5]

        method = getattr(base,action)
        if action == 'text':
            assert '帐号登录' == row[5]

        method(**params)
